<template>
  <page-header-wrapper :title="false">
    <a-card :bordered="false">
      <div class="table-page-search-wrapper">
        <RichText :loading="isLoading" ref="richText" :editContent="ruleContent" @btnGetTxt="btnSetTxt" :isLimitNumber="5000"></RichText>
        <a-button style="margin-top: 10px;" @click="onSetRule" type="primary">保存</a-button>
      </div>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import RichText from '@/components/RichText/RichText'
import { message } from 'ant-design-vue'
import { getRule, setRule } from '@/api/bank'
let self
export default {
  name: 'AdminRules',
  components: {
    RichText
  },
  data () {
    return {
      ruleContent: '',
      isLoading: false
    }
  },
  filters: {

  },
  created () {
    self = this
  },
  computed: {
  },
  mounted () {
    this.onGetRule()
  },
  methods: {
    btnSetTxt (content) {
      this.ruleContent = content
    },
    onGetRule () {
      // 获取积分规则
      self.isLoading = true
      getRule().then((res) => {
        self.isLoading = false
        // self.ruleContent = res.content
        this.$refs.richText.init(res.content)
      }).catch(() => {
        self.isLoading = false
      })
    },
    onSetRule () {
      // 获取积分规则
      self.isLoading = true
      setRule({ 'content': self.ruleContent }).then((res) => {
        self.isLoading = false
        if (res.is_ok === 'Y') {
          message.success('保存成功')
        }
      }).catch(() => {
        self.isLoading = false
      })
    }
  }
}
</script>

<style scoped>
</style>
